package com.party.course.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.enums.BusinessType;
import com.party.common.utils.poi.ExcelUtil;
import com.party.common.utils.spring.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.course.domain.CoachInfo;
import com.party.course.service.ICoachInfoService;
import com.party.common.core.page.TableDataInfo;

/**
 * 教练Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/course/Coach")
public class CoachInfoController extends BaseController {
    @Autowired
    private ICoachInfoService coachInfoService;

    /**
     * 查询教练列表
     */
//@RequiresPermissions("course:Coach:list")
    @GetMapping("/list")
    public TableDataInfo list(CoachInfo coachInfo) {
        startPage();
        List<CoachInfo> list = coachInfoService.findList(coachInfo);
        return getDataTable(list);
    }

    @GetMapping("/findCoachAmount")
    public TableDataInfo findCoachAmount(CoachInfo coachInfo) {
        startPage();
        List<CoachInfo> list = coachInfoService.findCoachAmount(coachInfo);
        return getDataTable(list);
    }

    /**
     * 查询教练列表
     *
     * @param coachInfo
     * @return
     */
    @GetMapping("/all")
    public AjaxResult findAll(CoachInfo coachInfo) {
        List<CoachInfo> list = coachInfoService.findAll(coachInfo);
        return AjaxResult.success(list);
    }

    /**
     * 定时任务，每天下午6点发送通知提醒 学管有多少条反馈未发
     * todo 缺少课前通知反馈
     * @return
     */
    @GetMapping("/taskFind")
    public AjaxResult taskFind() {
        //定时任务 需要手动注入bean
        ICoachInfoService bean = SpringUtils.getBean(ICoachInfoService.class);
        bean.taskFind();
        return AjaxResult.success();
    }

    /**
     * 导出教练列表
     */
    //@RequiresPermissions("course:Coach:export")
    @Log(title = "教练", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoachInfo coachInfo) {
        List<CoachInfo> list = coachInfoService.findList(coachInfo);
        ExcelUtil<CoachInfo> util = new ExcelUtil<CoachInfo>(CoachInfo.class);
        util.exportExcel(response, list, "教练数据");
    }

    /**
     * 获取教练详细信息
     */
    //@RequiresPermissions("course:Coach:query")
    @GetMapping(value = "/view/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(coachInfoService.view(id));
    }

    /**
     * 新增教练
     */
    //@RequiresPermissions("course:Coach:add")
    @Log(title = "教练", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CoachInfo coachInfo) {
        return toAjax(coachInfoService.add(coachInfo));
    }

    /**
     * 修改教练
     */
    //@RequiresPermissions("course:Coach:edit")
    @Log(title = "教练", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody CoachInfo coachInfo) {
        return toAjax(coachInfoService.updateEntity(coachInfo));
    }

    /**
     * 删除教练
     */
    //@RequiresPermissions("course:Coach:remove")
    @Log(title = "教练", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(coachInfoService.deleteIds(Arrays.asList(ids)));
    }
}
